package LeetCode;

import java.util.Scanner;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/4/21.
// 
public class 整数反转 {
    public static void main(String[] args) {
//        https://leetcode.cn/problems/reverse-integer/
        Scanner scan = new Scanner(System.in);
        int res = reverse(scan.nextInt());
        System.out.println(res);
    }
    public static int reverse(int x) {
        int flag = 1;
        if(x < 0){
            flag = -1;
            x *= -1;
        }
        if(x == -2147483648){
            return 0;
        }
        int temp = 0;
        while(x != 0){
            temp += x % 10;
//            System.out.println(temp);
            if(x / 10 != 0){
                if(temp > 214748364){
                    return 0;
                }else {
                    temp *= 10;
                }
            }
            x/=10;
//            System.out.println(x + "    " + temp);
        }
        if(temp<0){
            return 0;
        }else {
           return temp * flag;
        }
    }
}
